/* 空内容格式化 */
export function dataFormat(data, value) {
  return (!data) ? ((value) ? value : '--') : data
}

/* 静态文件匹配 */
export function matchValue(base, data, value, key) {
  try{
    return (!data && data != false) ? value : base[data][((key) ? key : 'title')]
  }catch(e){
    return value
  }  
}

/* 数字格式化 */
export function numFormat(data, fixed, msg) {
	var result = (parseFloat(data).toFixed(fixed))
	var defaultMsg = ((msg) ? msg : '--')
  return ((isNaN(result)) ? defaultMsg : result)
}


/*获取时间格式数据*/
export function dateFormat() {
  var date = null;
  if (arguments[0] == "" || arguments[0] == null) {
    date = new Date();
  } else {
    date = new Date(arguments[0]);
  }
  var year = date.getFullYear();
  var month = date.getMonth() > 8 ? date.getMonth() + 1 : "0" + (date.getMonth() + 1);
  var day = date.getDate() > 9 ? date.getDate() : "0" + date.getDate();
  var hour = date.getHours() > 9 ? date.getHours() : "0" + date.getHours();
  var min = date.getMinutes() > 9 ? date.getMinutes() : "0" + date.getMinutes();
  var scd = date.getSeconds() > 9 ? date.getSeconds() : "0" + date.getSeconds();
  if (arguments[1] == 1) {
    return year + "-" + month + "-" + day;
  } else if (arguments[1] == 2) {
    return year + "年" + month + "月" + day + "日 ";
  } else if (arguments[1] == 3) {
    return year + "-" + month + "-" + day + " " + hour + ":" + min;
  } else if (arguments[1] == 4) {
    return year + "/" + month + "/" + day + " " + hour + ":" + min;
  } else if (arguments[1] == 5) {
    return hour + ":" + min + ":" + scd;
  } else if (arguments[1] == 6) {
    return hour + ":" + min;
  }else if (arguments[1] == 8) {
    return [hour,min,scd]
  }
  let dateData = year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + scd;
  if (arguments[0] == "" || arguments[0] == null) {
    return "--"
  } else {
    return dateData
  }
}